import time
import pyautogui
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains

# 1. 创建浏览器驱动对象
driver = webdriver.Chrome()
# 最大化
driver.maximize_window()
# 2. 打开百度网页
driver.get("https://www.baidu.com/")

# 定位到触发文件选择窗口的元素
ele = driver.find_element(By.CSS_SELECTOR, "path[d='M1.85254 14.2326L5.08479 9.72923C5.81885 8.70649 7.25508 8.49716 8.25052 9.26783L17.4999 16.4286']")
# 点击元素，触发文件选择窗口弹出
ActionChains(driver).click(ele).perform()
time.sleep(2)  # 等待窗口弹出

# 使用 pyautogui 模拟键盘输入文件路径并确认
file_path = r"D:\soft\PycharmProjects\UiAutoProject\day04\img\1.png"
pyautogui.typewrite(file_path)
time.sleep(5)
# 使用键盘点击确认
pyautogui.press('shift')
pyautogui.press('enter')

time.sleep(5)
# 4. 关闭浏览器对象
driver.quit()